function CreateOfflineProject() {
    var _this = this;

    // 保存项目
    _this.save = function () {
        if(!_this.validate()){
            return;
        };
        $.ajax({
            url: appPath + '/admin/projectOffline/saveOfflineProject',
            async: false,
            type: 'POST',
            dataType:"json",
            data: $("#project_offline_form").serialize(),
            success: function(data){
                var code = data['code'];
                if(code){
                    layer.alert('保存成功', {icon: 1,  skin: 'layer-ext-moon', closeBtn:0}, function(index){
                    history.go(-1);
                    });
                }else{
                    layer.alert('操作失敗', {icon: 2,  skin: 'layer-ext-moon'});
                }
            }
        });
    }

    // 表单校验
    _this.validate = function () {
        var msg = "";
        var projectName = $.trim($("#projectName").val());
        var projectStartTime = $.trim($("#projectStartTime").val());
        var projectEndTime = $.trim($("#projectEndTime").val());
        var requireTime = $.trim($("#requireTime").val());
        var trainAddress = $.trim($("#trainAddress").val());
        var trainPerson = $.trim($("#trainPerson").val());
        if(!projectName){
            msg = "请填写项目名称！";
            layer.msg(msg);
            return false;
        }
        if(!projectStartTime){
            msg = "请填写项目开始时间！";
            layer.msg(msg);
            return false;
        }
        if(!projectEndTime){
            msg = "请填写项目结束时间！";
            layer.msg(msg);
            return false;
        }
        if(!requireTime){
            msg = "请填写项目学时！";
            layer.msg(msg);
            return false;
        }
        if(requireTime){
            var rule = /^[1-9]\d*$/;
            if(!rule.test(requireTime)){
                msg = "项目学时请填正整数！";
                layer.msg(msg);
                return false;
            }
        }
        if(!trainAddress){
            msg = "请填写培训地点！";
            return false;
        }
        if(!trainPerson){
            msg = "请填写授课老师！";
            layer.msg(msg);
            return false;
        }
        return true;
    }

}

var createOfflineProject = new CreateOfflineProject();